package com.cn.lyl.servlet.nav;

import com.alibaba.fastjson.JSONObject;
import com.cn.lyl.model.NavModel;
import com.cn.lyl.model.Page;
import com.cn.lyl.service.NavService;
import com.cn.lyl.service.impl.NavServiceImpl;
import com.cn.lyl.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/back/nav/list")
public class FindAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String title = req.getParameter("titles");
        NavModel navModel = new NavModel();
        navModel.setTitle(title);
        Page page=new Page();
        page.setPageCurr(Tool.curr(req.getParameter("page")));
        page.setPageSize(Tool.size(req.getParameter("limit")));
        navModel.setPage(page);
        NavService navService =new NavServiceImpl();

        List<NavModel> allNews = navService.findAllNav(navModel);
        navService.findAllNav(navModel);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",0);
        jsonObject.put("msg","");
        jsonObject.put("count",navService.getCount(navModel));
        jsonObject.put("data",allNews);
        resp.getWriter().print(jsonObject);

    }
}
